GraphNode

The GraphNode class represents a node in a graph structure.

Note: The GraphNode class is used extensively in the World module to build hierarchical tree structures. Users can instantiate GraphNode objects and customize them by inheriting from the class to add additional attributes or methods tailored to specific applications.

GraphNode class encapsulates the following attributes:

id (int or str)

Unique identifier for the node.

val (any, optional)

Value associated with the node. Defaults to the label if not provided.

neighbors (list of GraphNode objects)

List of neighboring nodes.

edges (list of int or float, optional)

List of edge weights corresponding to each neighboring node. Defaults to a list of 1s if not provided and neighbors are present.

isGoalState (bool)

Indicates if the node is a goal state.

_heatMapValue (int)

Internal attribute used for heat map visualization (default is 0).

Methods

__init__(self, label, neighbors: list, val=None, isGoalState: bool = False, edges: list = [])

Initializes a GraphNode instance.

Parameters

  • label (int or str): Unique identifier for the node.
  • neighbors (list of GraphNode objects): List of neighboring nodes.
  • val (any, optional): Value associated with the node. Defaults to label if not provided.
  • isGoalState (bool, optional): Indicates if the node is a goal state. Defaults to False.
  • edges (list of int or float, optional): List of edge weights corresponding to each neighboring node. Defaults to an empty list.

__str__(self) -> str

Returns a string representation of the GraphNode object.

Parameters

  • None

Returns

  • str: String representation of the GraphNode object.